package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.EntryOrder;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @Classname EntryOrderMapper
 * @Description TODO
 * @Date 2020/2/24 15:52
 * @Created by ASUS
 */
public interface EntryOrderMapper {

    @Insert("insert into entryorder (entryDate,entryTime,obligation,remark) values (#{entryDate},#{entryTime},#{obligation},#{remark})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Long insertEntry(EntryOrder entryOrder);

    @Delete("delete from entryorder where id = #{id}")
    int removeEntry(@Param("id") Long id);

    @Select("select * from entryorder where id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "entryFoods",many = @Many(select = "com.xuetang9.t9.hotel.mapper.EntryFoodMapper.queryByEntryId"))
    })
    EntryOrder queryById(@Param("id")Long id);

    @Update("update entryorder set entryDate=#{entryDate},entryTime=#{entryTime},obligation=#{obligation},remark=#{remark} where id = #{id}")
    int updateEntry(EntryOrder entryOrder);

    @Select("select * from entryorder where entryDate = #{nowDate}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "id", property = "entryFoods", many = @Many(select = "com.xuetang9.t9.hotel.mapper.EntryFoodMapper.queryByEntryId"))
    })
    List<EntryOrder> queryByDate(@Param("nowDate") String nowDate);
}
